In addition to setting opaque handle during domain
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 14 Oct 2005 15:01:11 +0000 (16:01 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 14 Oct 2005 15:01:11 +0000 (16:01 +0100)
creation, allow it to be changed after creation via
DOM0_SETDOMAINHANDLE operation (and libxc
xc_domain_sethandle, and via Pyhton wrapper fn).

Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_domain.c
tools/libxc/xenctrl.h
tools/python/xen/lowlevel/xc/xc.c
xen/common/dom0_ops.c
xen/include/public/dom0_ops.h

index 6404b3f307ad575cc81483f17e2ba6307f9f6c8c..4b43ed9bf9ccfe9e93e83f57486aab17d11725e8 100644 (file)
@@ -334,6 +334,16 @@ int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
     return do_dom0_op(xc_handle, &op);
 }
 
+int xc_domain_sethandle(int xc_handle, uint32_t domid, 
+                        xen_domain_handle_t handle)
+{
+    dom0_op_t op;
+    op.cmd = DOM0_SETDOMAINHANDLE;
+    op.u.setdomainhandle.domain = (domid_t)domid;
+    memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
+    return do_dom0_op(xc_handle, &op);
+}
+
 /*
  * Local variables:
  * mode: C
index a5bfb62ac8d55c2791ac42a005c8597428c01b6c..464810edf5f01531b2ab693202514bedab693812 100644 (file)
@@ -257,6 +257,8 @@ long long xc_domain_get_cpu_usage(int xc_handle,
                                   domid_t domid,
                                   int vcpu);
 
+int xc_domain_sethandle(int xc_handle, uint32_t domid, 
+                        xen_domain_handle_t handle);
 
 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
 int xc_shadow_control(int xc_handle,
index 4108e1ff30092a3e1bcb7efb9ba7f5cd3978e7fa..bd554284ffcf4f4bb39ee5ee22fbb91819f4ba51 100644 (file)
@@ -242,6 +242,47 @@ static PyObject *pyxc_domain_setcpuweight(PyObject *self,
     return zero;
 }
 
+static PyObject *pyxc_domain_sethandle(PyObject *self,
+                                       PyObject *args,
+                                       PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    int i;
+    uint32_t dom;
+    PyObject *pyhandle;
+    xen_domain_handle_t handle;
+
+    static char *kwd_list[] = { "dom", "handle", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iO", kwd_list, 
+                                      &dom, &pyhandle) )
+        return NULL;
+
+    if ( !PyList_Check(pyhandle) || 
+         (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) )
+    {
+    out_exception:
+        errno = EINVAL;
+        PyErr_SetFromErrno(xc_error);
+        return NULL;
+    }
+
+    for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
+    {
+        PyObject *p = PyList_GetItem(pyhandle, i);
+        if ( !PyInt_Check(p) )
+            goto out_exception;
+        handle[i] = (uint8_t)PyInt_AsLong(p);
+    }
+
+    if ( xc_domain_sethandle(xc->xc_handle, dom, handle) < 0 )
+        return PyErr_SetFromErrno(xc_error);
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
 static PyObject *pyxc_domain_getinfo(PyObject *self,
                                      PyObject *args,
                                      PyObject *kwds)
@@ -873,6 +914,14 @@ static PyMethodDef pyxc_methods[] = {
       " cpuweight [float, 1]: VCPU being pinned.\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "domain_sethandle", 
+      (PyCFunction)pyxc_domain_sethandle,
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Set domain's opaque handle.\n"
+      " dom [int]:            Identifier of domain.\n"
+      " handle [list of 16 ints]: New opaque handle.\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { "domain_getinfo", 
       (PyCFunction)pyxc_domain_getinfo, 
       METH_VARARGS | METH_KEYWORDS, "\n"
index d1d2bfcefa8201fbcbc569c8d79182ebd1508513..9541adbbf8833a65a8a4434b1e6ffbdde6175c7c 100644 (file)
@@ -557,6 +557,21 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     }
     break;
 
+    case DOM0_SETDOMAINHANDLE:
+    {
+        struct domain *d; 
+        ret = -ESRCH;
+        d = find_domain_by_id(op->u.setdomainhandle.domain);
+        if ( d != NULL )
+        {
+            memcpy(d->handle, op->u.setdomainhandle.handle,
+                   sizeof(xen_domain_handle_t));
+            put_domain(d);
+            ret = 0;
+        }
+    }
+    break;
+
 #ifdef PERF_COUNTERS
     case DOM0_PERFCCONTROL:
     {
index 528f9afc69ba2dad0ee64e1a214810701d6d7946..9402feb30eba0559bf1ac88c1eb71fd6e22b2fb1 100644 (file)
@@ -405,6 +405,11 @@ typedef struct {
     unsigned int max;           /* maximum number of vcpus */
 } dom0_max_vcpus_t;
 
+#define DOM0_SETDOMAINHANDLE 44
+typedef struct {
+    domid_t domain;
+    xen_domain_handle_t handle;
+} dom0_setdomainhandle_t;
 
 typedef struct {
     uint32_t cmd;
@@ -443,6 +448,7 @@ typedef struct {
         dom0_platform_quirk_t    platform_quirk;
         dom0_physical_memory_map_t physical_memory_map;
         dom0_max_vcpus_t         max_vcpus;
+        dom0_setdomainhandle_t   setdomainhandle;
         uint8_t                  pad[128];
     } u;
 } dom0_op_t;